Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

261
Visualizações
Why when I set the value of an hidden input to a value of an array of objects it makes every item in the hidden input array into [object Object]

I have this code:

for(let i =0; i < upbtn.length; i++){
  upbtn[i].addEventListener('click', function(){
    let whichTopic = i
    if(whichTopic == 0){
      return true
    }
    else{
      let arr = coursenewtopics.value
      arr = JSON.parse(arr)
      arraymove(arr, i, i-1)
      coursenewtopics.value = arr
      console.log(arr)
      console.log(coursenewtopics.value)
      //changeordertopicsform.submit()
    }
  })
}

I am trying to sort an array from an hidden input then set the value of the hidden input to the sorted array, I console logged the results from the sorted array(arr)

[
    {
        "type": "text",
        "name": "",
        "text": ""
    },
    {
        "type": "text",
        "name": "2",
        "text": ""
    },
    {
        "type": "text",
        "name": "1",
        "text": ""
    },
    {
        "type": "text",
        "name": "3",
        "text": ""
    },
    {
        "type": "text",
        "name": "4",
        "text": ""
    }
]

and the results are what I want, however when after I put this value I just logged of arr to the hidden input, then console log the value of the hidden input becomes:

[object Object],[object Object],[object Object],[object Object],[object Object]

why does JavaScript act this? how do I fix this an put the values into the hidden input without making them go [object Object]? I need them for a form later on.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

so your problem is 'How to display an array of object literally'.

you can try JSON.stringify(arr, null, ' ')

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda